export { isVNode } from "vue";

export function isArray(val: any): boolean {
	return Array.isArray(val);
}

export function isString(val: any): boolean {
	return typeof val === "string";
}

export function isObject(val: any): boolean {
	return val !== null && typeof val === "object";
}

export function isPromise(val: any): boolean {
	return (isObject(val) || isFunction(val)) && isFunction(val.then) && isFunction(val.catch);
}

const objectToString = Object.prototype.toString;
const toTypeString = (value: any) => objectToString.call(value);

export function isDate(val: any): boolean {
	return toTypeString(val) === "[object Date]";
}

export function isFunction(val: any): boolean {
	return typeof val === "function";
}

export function isUndefined(val: any): boolean {
	return typeof val === undefined;
}

export function isBoolean(val: any): boolean {
	return typeof val === "boolean";
}

export function isNumber(val: any): boolean {
	return typeof val === "number";
}

export const isEmpty = (val: any): boolean => {
	if (val === undefined || val === null) {
		return true;
	}

	if (isString(val) && val.trim() === "") {
		return true;
	}

	if (isArray(val) && !val.length) {
		return true;
	}

	if (isObject(val) && JSON.stringify(val) === "{}") {
		return true;
	}

	return false;
};

export const isElement = (e: any) => {
	if (typeof Element === "undefined") return false;
	return e instanceof Element;
};

export const isStringNumber = (val: any) => {
	if (!isString(val)) {
		return false;
	}
	return !Number.isNaN(Number(val));
};
